const validateLng = (rule, value, callback) => {
  const strVal = value.replace(/\s*/g, "");
  const NumVal = Number(strVal);
  switch (true) {
    case !strVal:
      callback(new Error('请输入经度'));
      break;

    case NumVal != 0 && !NumVal:
      callback(new Error('经度必须是数字类型值'));
      break;

    case 0 > NumVal:
      callback(new Error('经度小于0'));
      break;

    case NumVal > 180:
      callback(new Error('经度大于180'));
      break;

    default:
      callback();
      break;
  }
};

const validateLngRange = (rule, value, callback) => {
  const strVal = value.replace(/\s*/g, "");
  const NumVal = Number(strVal);
  switch (true) {
    case NumVal != 0 && !NumVal:
      callback(new Error('经度必须是数字类型值'));
      break;

    case 0 > NumVal:
      callback(new Error('经度小于0'));
      break;

    case NumVal > 180:
      callback(new Error('经度大于180'));
      break;

    default:
      callback();
      break;
  }
};

const validateLat = (rule, value, callback) => {
  const strVal = value.replace(/\s*/g, "");
  const NumVal = Number(strVal);
  switch (true) {
    case !strVal:
      callback(new Error('请输入纬度'));
      break;

    case NumVal != 0 && !NumVal:
      callback(new Error('纬度必须是数字类型值'));
      break;

    case 0 > NumVal:
      callback(new Error('纬度小于0'));
      break;

    case NumVal > 90:
      callback(new Error('纬度大于90'));
      break;

    default:
      callback();
      break;
  }
};

const validateLatRange = (rule, value, callback) => {
  const strVal = value.replace(/\s*/g, "");
  const NumVal = Number(strVal);
  switch (true) {
    case NumVal != 0 && !NumVal:
      callback(new Error('纬度必须是数字类型值'));
      break;

    case 0 > NumVal:
      callback(new Error('纬度小于0'));
      break;

    case NumVal > 90:
      callback(new Error('纬度大于90'));
      break;

    default:
      callback();
      break;
  }
};

const validateHeight = (rule, value, callback) => {
  const strVal = value.replace(/\s*/g, "");
  const NumVal = Number(strVal);
  switch (true) {
    case !strVal:
      callback(new Error('请输入高度'));
      break;

    case NumVal != 0 && !NumVal:
      callback(new Error('高度必须是数字类型值'));
      break;

    case 0 > NumVal:
      callback(new Error('高度小于0'));
      break;

    default:
      callback();
      break;
  }
};

const validateHeightRange = (rule, value, callback) => {
  const strVal = value.replace(/\s*/g, "");
  const NumVal = Number(strVal);
  switch (true) {
    case NumVal != 0 && !NumVal:
      callback(new Error('高度必须是数字类型值'));
      break;

    case 0 > NumVal:
      callback(new Error('高度小于0'));
      break;

    default:
      callback();
      break;
  }
};

const validateHeading = (rule, value, callback) => {
  const strVal = value.replace(/\s*/g, "");
  const NumVal = Number(strVal);
  switch (true) {
    case NumVal != 0 && !NumVal:
      callback(new Error('偏航角必须是数字类型值'));
      break;

    case -180 > NumVal || NumVal > 180:
      callback(new Error('偏航角区间为 -180 ~ 180'));
      break;

    default:
      callback();
      break;
  }
};

const validatePitch = (rule, value, callback) => {
  const strVal = value.replace(/\s*/g, "");
  const NumVal = Number(strVal);
  switch (true) {
    case NumVal != 0 && !NumVal:
      callback(new Error('俯仰角必须是数字类型值'));
      break;

    case -180 > NumVal || NumVal > 180:
      callback(new Error('俯仰角区间为 -180 ~ 180'));
      break;

    default:
      callback();
      break;
  }
};

const validateRoll = (rule, value, callback) => {
  const strVal = value.replace(/\s*/g, "");
  const NumVal = Number(strVal);
  switch (true) {
    case NumVal != 0 && !NumVal:
      callback(new Error('翻滚角必须是数字类型值'));
      break;

    case -180 > NumVal || NumVal > 180:
      callback(new Error('翻滚角区间为 -180 ~ 180'));
      break;

    default:
      callback();
      break;
  }
};

const validateScale = (rule, value, callback) => {
  const strVal = value.replace(/\s*/g, "");
  const NumVal = Number(strVal);
  switch (true) {
    case !strVal:
      callback(new Error('请输入缩放值'));
      break;

    case NumVal != 0 && !NumVal:
      callback(new Error('缩放值必须是数字类型值'));
      break;

    case 0 >= NumVal:
      callback(new Error('缩放值小于等于0'));
      break;

    default:
      callback();
      break;
  }
};

const validateServerUrl = (rule, value, callback) => {
  if (value.replace(/\s*/g, "") === '') {
    callback(new Error('请输入服务地址'));
  } else {
    callback();
  }
};

const validateLineWidth = (rule, value, callback) => {
  const reg = /^\+?[1-9][0-9]*$/;
  if (value.replace(/\s*/g, "") === '') {
    callback(new Error('请输入线宽'));
  } else if (!reg.test(value)) {
    callback(new Error('线宽必须为正整数'));
  } else {
    callback();
  }
};

const validateHeightField = (rule, value, callback) => {
  if (value.replace(/\s*/g, "") === '') {
    callback(new Error('请选择高度字段'));
  } else {
    callback();
  }
};

export { validateLng, validateLngRange, validateLat, validateLatRange, validateHeight, validateHeightRange, validateHeading, validatePitch, validateRoll, validateScale, validateServerUrl, validateLineWidth, validateHeightField };